/*
 * Copyright (C) 2025 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <filesystem>
#include <fstream>
#include <gtest/gtest.h>

#include "read_lines_core.h"

namespace OHOS::FileManagement::ModuleFileIO::Test {
using namespace testing;
using namespace testing::ext;
using namespace std;

class ReadLinesCoreTest : public testing::Test {
public:
    static filesystem::path tempFilePath;
    static void SetUpTestCase(void);
    static void TearDownTestCase(void);
    void SetUp();
    void TearDown();
};

filesystem::path ReadLinesCoreTest::tempFilePath;

void ReadLinesCoreTest::SetUpTestCase(void)
{
    tempFilePath = filesystem::temp_directory_path() / "read_lines_test_file.txt";
    ofstream(tempFilePath) << "Test content\n123\n456";
    ofstream(tempFilePath).close();
    GTEST_LOG_(INFO) << "SetUpTestCase";
}

void ReadLinesCoreTest::TearDownTestCase(void)
{
    filesystem::remove(tempFilePath);
    GTEST_LOG_(INFO) << "TearDownTestCase";
}

void ReadLinesCoreTest::SetUp(void)
{
    GTEST_LOG_(INFO) << "SetUp";
}

void ReadLinesCoreTest::TearDown(void)
{
    GTEST_LOG_(INFO) << "TearDown";
}

/**
 * @tc.name: ReadLinesCoreTest_DoReadLines_001
 * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for FAILED.
 * @tc.size: MEDIUM
 * @tc.type: FUNC
 * @tc.level Level 1
 */
HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_001, testing::ext::TestSize.Level1)
{
    GTEST_LOG_(INFO) << "ReadLinesCoreTest-begin ReadLinesCoreTest_DoReadLines_001";

    string path = "ReadLinesCoreTest_DoReadLines_001";
    Options option;
    option.encoding = "utf-8";
    auto res = ReadLinesCore::DoReadLines(path, option);
    EXPECT_EQ(res.IsSuccess(), false);

    GTEST_LOG_(INFO) << "ReadLinesCoreTest-end ReadLinesCoreTest_DoReadLines_001";
}

/**
 * @tc.name: ReadLinesCoreTest_DoReadLines_002
 * @tc.desc: Test function of ReadLinesCore::DoReadLines interface for FAILED.
 * @tc.size: MEDIUM
 * @tc.type: FUNC
 * @tc.level Level 1
 */
HWTEST_F(ReadLinesCoreTest, ReadLinesCoreTest_DoReadLines_002, testing::ext::TestSize.Level1)
{
    GTEST_LOG_(INFO) << "ReadLinesCoreTest-begin ReadLinesCoreTest_DoReadLines_002";

    string path = "ReadLinesCoreTest_DoReadLines_002";
    Options option;
    option.encoding = "utf-16";
    auto res = ReadLinesCore::DoReadLines(path, option);
    EXPECT_EQ(res.IsSuccess(), false);

    GTEST_LOG_(INFO) << "ReadLinesCoreTest-end ReadLinesCoreTest_DoReadLines_002";
}

} // namespace OHOS::FileManagement::ModuleFileIO::Test